package com.cp.yn.dialog

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import com.cp.yn.R
import com.cp.yn.databinding.DialogCaptchaBinding
import com.lxj.xpopup.core.CenterPopupView
import com.common.base.http.main.ApiConfig
import com.common.base.manager.ConfigManager
import com.common.base.tools.extend.click
import com.common.base.tools.extend.loadUrl
import com.common.base.tools.obj.KeyboardUtil

/**
 * 三疯
 * *************************
 *
 * *************************
 */
class DialogCaptcha(context: Context, var captchaPath: String, var callback: (String) -> Unit)
    : CenterPopupView(context) {

    private val viewBinding by lazy {
        DialogCaptchaBinding.bind(contentView)
    }
    override fun getImplLayoutId(): Int {
        return  R.layout.dialog_captcha
    }
    override fun onCreate() {
        super.onCreate()
        viewBinding.codeCaptcha.loadUrl(ConfigManager.configBean?.imageUrl + captchaPath)
        viewBinding.codeConfirm.click {
            dismiss()
            callback.invoke(viewBinding.codeInput.text.toString())
        }


    }

    override fun onShow() {
        super.onShow()
        KeyboardUtil.showInputKeyboad(viewBinding.codeInput,  context as AppCompatActivity)
    }
}

